package com.kstech.mp3604.fragments

import androidx.lifecycle.ViewModelProvider
import com.kstech.mp3604.base.BaseDialogFragment
import com.kstech.mp3604.base.Global.LOGIN_SET_PARAM_PASSWORD
import com.kstech.mp3604.base.HomeViewModel
import com.kstech.mp3604.databinding.FragmentDialogLoginSetParamBinding


/**
 * 对话框 输入密码方可以进入参数设置界面
 */
class DialogLoginSetParamFragment() :
    BaseDialogFragment<FragmentDialogLoginSetParamBinding>(FragmentDialogLoginSetParamBinding::inflate) {

    private lateinit var mViewModel: HomeViewModel

    override fun onInitView() {
        mViewModel = ViewModelProvider(requireActivity())[HomeViewModel::class.java]
        binding.apply {
            password.setText("")
            submit.setOnClickListener {
                val psw = password.text.toString().trim()
                if (psw == LOGIN_SET_PARAM_PASSWORD) {
                    dialog!!.cancel()
                    mViewModel.loginSetParamListener.loginSuccess()
                } else {
                    dialog!!.cancel()
                    mViewModel.loginSetParamListener.loginFail()
                }
            }
            closeDialog.setOnClickListener {
                dialog!!.cancel()
            }
        }
    }
}